/**
 * representation of trailer that can be added to a transporter's hitch
 * @author Lukas Koell
 * @author David Medenjak
 * @author Johannes Riedmann
 */

public class Trail extends Transporter implements ITrail{
    
    /**
     * Constructor.
     * a trail consists of a number of hitches and a different departments
     * @param kupplungen number of hitches of the trail
     * @param abteile array of departments of the trail
     */
    public Trail(int kupplungen, Compartment[] abteile) {
        super(kupplungen, abteile);
    }
    
    /**
     * if trail has free hitch, trail will be added (return true) else returns false
     * @param hitches hitches of trail
     * @return true if trail has free hitch, else false
     */
    public boolean hangTo(Hitch[] hitches){
        for(int i = 0; i < hitches.length; i++){
            if(hitches[i] != null){
                if(hitches[i].getObject() == null){
                    hitches[i].attachObject(this);
                    return true;
                }
            }
        }
        System.out.println("No free coupling was found for the trailer");
        return false;
    }
    
    public Trail unHang(){
        return this;
    }

}
